package com.lkd.controller;

import com.lkd.dto.SkuClassDto;
import com.lkd.dto.SkuClassPageDto;
import com.lkd.entity.Sku;
import com.lkd.entity.SkuClass;
import com.lkd.result.PageBean;
import com.lkd.result.Result;
import com.lkd.service.SkuClassService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/skuClass")
@Slf4j
public class SkuClassController {

    @Autowired
    private SkuClassService skuClassService;

    //新增分类
    @PostMapping
    public Result save(@RequestBody SkuClassDto skuClassDto) {
        Boolean result = skuClassService.save(skuClassDto);
        return Result.success(result);
    }

    //分类搜索
    @GetMapping("/search")
    public Result getByPage(SkuClassPageDto skuClassPageDto){
        PageBean pageBean = skuClassService.getByPage(skuClassPageDto);
        return Result.success(pageBean);
    }

    //分类回显
    @GetMapping("/{classId}")
    public Result getById(@PathVariable String classId) {
        SkuClassDto skuClassDto=skuClassService.getById(classId);
        return Result.success(skuClassDto);
    }
    //分类修改
    @PutMapping
    public Result updateById(@RequestBody SkuClassDto skuClassDto) {
        Boolean skuClass = skuClassService.updateById(skuClassDto);
        return Result.success(skuClass);
    }

    //删除分类
    @DeleteMapping("/{classId}")
    public Result deleteById(@PathVariable String classId){
        Boolean result = skuClassService.deleteById(classId);
        return Result.success(result);

    }

}
